/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.CosBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.SoapProtocol;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.mailbox.RetentionPolicyManager;
/*    */ import com.zimbra.soap.JaxbUtil;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest;
/*    */ import com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse;
/*    */ import com.zimbra.soap.admin.type.CosSelector;
/*    */ import com.zimbra.soap.admin.type.CosSelector.CosBy;
/*    */ import com.zimbra.soap.mail.type.Policy;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CreateSystemRetentionPolicy
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   static final String SYSTEM_RETENTION_POLICY_ATTR = "zimbraMailPurgeSystemPolicy";
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 45 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 47 */     CreateSystemRetentionPolicyRequest req = (CreateSystemRetentionPolicyRequest)JaxbUtil.elementToJaxb(request);
/*    */     
/* 49 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/*    */ 
/* 52 */     Entry entry = prov.getConfig();
/*    */     
/*    */ 
/* 55 */     CosSelector cosSelector = req.getCos();
/*    */     
/* 57 */     if (cosSelector != null) {
/* 58 */       entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
/* 59 */       if (entry == null) {
/* 60 */         throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
/*    */       }
/*    */     }
/*    */     
/* 64 */     checkSetRight(entry, zsc, context, this);
/*    */     
/* 66 */     Policy keep = req.getKeepPolicy();
/* 67 */     Policy purge = req.getPurgePolicy();
/* 68 */     if ((keep == null) && (purge == null)) {
/* 69 */       throw ServiceException.INVALID_REQUEST("No keep or purge policy specified.", null);
/*    */     }
/* 71 */     if ((keep != null) && (purge != null)) {
/* 72 */       throw ServiceException.INVALID_REQUEST("Cannot specify both keep and purge policy.", null);
/*    */     }
/*    */     Policy newPolicy;
/*    */     Policy newPolicy;
/* 76 */     if (keep != null) {
/* 77 */       newPolicy = RetentionPolicyManager.getInstance().createSystemKeepPolicy(entry, keep.getName(), keep.getLifetime());
/*    */     } else {
/* 79 */       newPolicy = RetentionPolicyManager.getInstance().createSystemPurgePolicy(entry, purge.getName(), purge.getLifetime());
/*    */     }
/* 81 */     CreateSystemRetentionPolicyResponse res = new CreateSystemRetentionPolicyResponse(newPolicy);
/* 82 */     return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
/*    */   }
/*    */   
/*    */   static void checkSetRight(Entry entry, ZimbraSoapContext zsc, Map<String, Object> context, AdminDocumentHandler handler)
/*    */     throws ServiceException
/*    */   {
/* 88 */     AdminAccessControl.SetAttrsRight sar = new AdminAccessControl.SetAttrsRight();
/* 89 */     sar.addAttr("zimbraMailPurgeSystemPolicy");
/* 90 */     handler.checkRight(zsc, context, entry, sar);
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 95 */     notes.add("Need set attr right on attribute zimbraMailPurgeSystemPolicy");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CreateSystemRetentionPolicy.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */